 //
//  HomeViewController.m
//  CheekiOS
//
//  Created by mac on 2017/5/9.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HomeViewController.h"
#import "YSLDraggableCardContainer.h"//卡片
#import "CardView.h"//卡片
#import "HcardHttpmanager.h"//请求
#import "HcardUserModel.h"//模型
#import "CityView.h"//城市选择
#import "UIImage+GIF.h"
#import "GGActionSheet.h"//弹出搜索选项
#import "HYSegmentControl.h"//滑块
#import "ScreeningViewController.h"//筛选搜索
//清除位置信息
#import "HomeRemovelocationView.h"
#import "HomePromptRemoveView.h"

#import "HomeStrangCollionViewController.h"


@interface HomeViewController ()<YSLDraggableCardContainerDelegate, YSLDraggableCardContainerDataSource, CLLocationManagerDelegate,CityViewDelegate, GGActionSheetDelegate,CardViewDelegate,HomeRemovelocationViewDelegate,HomePromptRemoveViewDelegate>
{

    int  _page;//页数
    int _rows;
    NSString *_priorityStr;//活跃
    NSString *_city;//城市
    NSString *_sex;//性别
    NSString *_maxAge;//大
    NSString *_minAge;//小
    NSString *_distance;//距离
    NSNumber *_videoUser;//视频用户
    NSString *_sort ;//排序
    //坐标
    CGFloat longitude;
    CGFloat latitude;
    
    //字体
    CGFloat titleSize;
    CGFloat titleSclectSize;

}
@property (nonatomic, strong) YSLDraggableCardContainer *container;//卡片
@property (nonatomic, strong) NSMutableArray *dataArr;//数据

@property (nonatomic, strong) CityView *cityView;//城市
@property (nonatomic, strong) UIButton *leftBtn;//选择城市
@property (nonatomic, strong) UIButton *rightBtn;//筛选条件
@property (nonatomic, strong) UIButton *btnLeft;
@property (nonatomic, strong) UIButton *btnRight;
@property (nonatomic, strong) CardView *cardView;
@property (nonatomic, strong) UIImageView *Nodataimg;//无数据

@property (nonatomic, strong) UILabel *slidingLab;//提示滑动
@property (nonatomic, strong) CLLocationManager * locationManger;//定位
@property (nonatomic, strong) HcardUserModel *Cardmodel;//模型
@property (nonatomic, strong) NSString *HotStr;//热门 附近 最新

@property (nonatomic, strong) UIImageView *leftsliImg;//左右滑动图
@property (nonatomic, strong) UIImageView *rightsliImg;
//@property(nonatomic,strong) GGActionSheet *actionSheetImg;//可以添加图片的方法    [self.actionSheetImg showGGActionSheet];
@property(nonatomic,strong) GGActionSheet *actionSheetTitle;
/**
 清除位置并推出
 */
@property (nonatomic, strong)HomeRemovelocationView *removeView;
@property (nonatomic, strong)HomePromptRemoveView *romptRemove;
//个人信息数据
@property (nonatomic, strong)UserpersionlInfoModel *UserInfomodel;
@property (nonatomic, strong)UIView *PhotoAuditView;
@end

@implementation HomeViewController

- (void)viewWillAppear:(BOOL)animated{
    
    
 
    [self setNavgationBarHidden];
    
    [self UserInfoRequestDate];

}
- (void)UserInfoRequestDate{
    [HcardHttpmanager getPersionalUserInfosuccess:^(id sucess) {
        self.UserInfomodel = [UserpersionlInfoModel mj_objectWithKeyValues:sucess[@"res"]];
        //头像没有经过审核

        if ([self.UserInfomodel.photoStatus isEqualToString:@"0"]) {
            [self PhotoAuditdateView];
        }else{
            
            [self RemovePhotoAuditdateView];
        }
    } failure:^(NSError *error) {
        
    }];

}
- (void)viewDidLoad{
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sendRequest) name:@"blackFriendNotification" object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(HomeStrongControllerRightDirection) name:@"rigthNSNotificationHomeStrang" object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(HomeStrongControllerLeftDirection) name:@"leftNSNotificationHomeStrang" object:nil];
    
    
    [super viewDidLoad];
    UIView *BarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 64)];
    BarView.backgroundColor = Colorbackground;
    self.view.backgroundColor = [UIColor whiteColor];
//    _city = @"全国";
    
    
    //数据数组
    self.dataArr = [[NSMutableArray alloc] init];
    _page = 1;//页数
    
    _sort = @"4";//类型
    _priorityStr = @"0";//活跃
    _sex = nil;
    //坐标
    NSString *lon = [[NSUserDefaults standardUserDefaults] objectForKey:@"longitude"];
    longitude = lon.doubleValue;
    NSString *lat = [[NSUserDefaults standardUserDefaults] objectForKey:@"latitude"];
    latitude = lat.doubleValue;
    //定位
    [self didLocation];
    //第一次进入请求
    [self sendRequest];
    

  
    
    
    //城市选择按钮
    _leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_leftBtn setTitle:[NSString stringWithFormat:@"%@",_city] forState:UIControlStateNormal];
    _leftBtn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft ;//设置文字位置，现设为居左，默认的是居中
    //城市选择图片
    UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"placeholder_icon"]];
    
    imgView.frame = CGRectMake(15, 26, 16*SCREEN_WIDTH_RATIO47, 21*SCREEN_WIDTH_RATIO47);
    
//    [BarView addSubview:imgView];
    
    if (iPhone5) {
        _leftBtn.titleLabel.font = Font(13);
        _leftBtn.frame = CGRectMake(imgView.right+5, 25, 50*SCREEN_WIDTH_RATIO47, 30*SCREEN_WIDTH_RATIO47);
        titleSize = 13;
        titleSclectSize = 13;
    }else if (iPhone6){
        _leftBtn.titleLabel.font = Font(14);
        _leftBtn.frame = CGRectMake(imgView.right+5, 25, 50*SCREEN_WIDTH_RATIO47, 30*SCREEN_WIDTH_RATIO47);
        titleSize = 17;
        titleSclectSize = 17;
    }else if (iPhone6p){
        _leftBtn.titleLabel.font = Font(14);
        _leftBtn.frame = CGRectMake(imgView.right+5, 25, 50*SCREEN_WIDTH_RATIO47, 30*SCREEN_WIDTH_RATIO47);
        titleSize = 17;
        titleSclectSize = 17;
    }else{
        titleSize = 17;
        titleSclectSize = 17;
    }
    //城市按钮
//    [_leftBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    [_leftBtn addTarget:self action:@selector(createPickview) forControlEvents:UIControlEventTouchUpInside];
//    [BarView addSubview:_leftBtn];
//    
//    _btnLeft = [UIButton buttonWithType:UIButtonTypeCustom];
//    _btnLeft.frame = CGRectMake(0, 25, imgView.width+_leftBtn.width+15*SCREEN_WIDTH_RATIO47, 30*SCREEN_WIDTH_RATIO47);
//    [_btnLeft addTarget:self action:@selector(createPickview) forControlEvents:UIControlEventTouchUpInside];
//    [BarView addSubview:_btnLeft];
    //segment
    
//    NSMutableArray *titleSourcd = [NSMutableArray arrayWithObjects:@"热门", @"附近", @"最新", nil];
        NSMutableArray *titleSourcd = [NSMutableArray arrayWithObjects:@"附近",nil];

    
    CGFloat TopsegmentFloat ;
    CGFloat segmentControlFloat;
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad){
        NSLog(@"ipad");
        TopsegmentFloat =23;
        segmentControlFloat = 18;
    }else{
        TopsegmentFloat = 42;
        segmentControlFloat = 30;
        NSLog(@"iphone or ipod");
    }
    
    WEAKSELF;
    HYSegmentControl *segmentControl = [HYSegmentControl segmentColor:CGRectMake(KScreenWidth/4, BarView.height-TopsegmentFloat*SCREEN_WIDTH_RATIO47, KScreenWidth/2, segmentControlFloat*SCREEN_WIDTH_RATIO47) titleSource:titleSourcd titleColor:[UIColor grayColor] selectTitleColor:[UIColor blackColor] titleFont:[UIFont systemFontOfSize:titleSize] selectTiteFont:[UIFont systemFontOfSize:titleSclectSize] backgroundColor:Colorbackground bottomLingColor:Theme_Color_White];
    
    segmentControl.finished = ^(UIButton *btn) {
        NSLog(@"btn = %@", btn.currentTitle);
        _HotStr = btn.currentTitle;
        if (btn.tag == 0) {
//            _leftBtn.hidden = NO;
//            _btnLeft.hidden = NO;
//            _rightBtn.hidden = YES;
//            _btnRight.hidden = YES;
            imgView.hidden = NO;
            _page = 1;
            _sex = nil;
            _maxAge = nil;
            _minAge = nil;
            _sort = @"4";
            _priorityStr = @"0";
            [weakSelf sendRequest];
            
        }
//        else{
//            if (btn.tag == 1) {
//                _sort = @"4";
//            }else{
//                _sort = @"2";
//            }
//            
//            _leftBtn.hidden = YES;
//            
//            _btnLeft.hidden = YES;
//            _rightBtn.hidden = NO;
//            _btnRight.hidden = NO;
//            
//            
//            
//            imgView.hidden = YES;
//            [weakSelf sendRequest];
//        }
    };
    
    [BarView addSubview:segmentControl];
    
    //右侧筛选按钮
    _rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_rightBtn setImage:[UIImage imageNamed:@"home_screen_icon"] forState:UIControlStateNormal];
    [_rightBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
//    _rightBtn.hidden = YES;
    _rightBtn.frame = CGRectMake(BarView.width-35*SCREEN_WIDTH_RATIO47, 25, 20*SCREEN_WIDTH_RATIO47, 21*SCREEN_WIDTH_RATIO47);
    [BarView addSubview:_rightBtn];

    _btnRight = [UIButton buttonWithType:UIButtonTypeCustom];

    [_btnRight addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
    _btnRight.frame = CGRectMake(BarView.width-50*SCREEN_WIDTH_RATIO47, 25, 50*SCREEN_WIDTH_RATIO47, 40*SCREEN_WIDTH_RATIO47);
//    _btnRight.hidden = YES;
    [BarView addSubview:_btnRight];

    CGFloat slidingTopFloat ;
    
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad){
        NSLog(@"ipad");
        slidingTopFloat =35;
    }else{
        slidingTopFloat = 70;
        NSLog(@"iphone or ipod");
    }
  
    //滑动提示
    _slidingLab = [[UILabel alloc]init];
    _slidingLab.textAlignment = NSTextAlignmentCenter;
    _slidingLab.font = [UIFont fontWithName:@"Futura-Medium" size:16];
    _slidingLab.text = @"左滑无感   右滑喜欢";
    _slidingLab.hidden = YES;
    _slidingLab.textColor = [UIColor grayColor];
    [self.view addSubview:_slidingLab];
    [_slidingLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(KScreenWidth/2);
        make.bottom.equalTo(self.view).offset(-slidingTopFloat*SCREEN_WIDTH_RATIO47);
        make.height.mas_equalTo(30);
        make.left.mas_equalTo(KScreenWidth/4);
    }];
    
    //左右图片
    _leftsliImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"left_slip"]];
    [self.view addSubview:_leftsliImg];
    [_leftsliImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(20*SCREEN_WIDTH_RATIO47);
        make.height.mas_equalTo(20*SCREEN_WIDTH_RATIO47);
        make.right.equalTo(_slidingLab.mas_left);
        make.bottom.equalTo(self.view).offset(-(slidingTopFloat-5)*SCREEN_WIDTH_RATIO47);
    }];
    
    _leftsliImg.hidden = YES;
    _rightsliImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"right_slip"]];
    [self.view addSubview:_rightsliImg];
    [_rightsliImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(20*SCREEN_WIDTH_RATIO47);
        make.height.mas_equalTo(20*SCREEN_WIDTH_RATIO47);
        make.left.equalTo(_slidingLab.mas_right);
        make.bottom.equalTo(self.view).offset(-(slidingTopFloat-5)*SCREEN_WIDTH_RATIO47);
    }];
    _rightsliImg.hidden = YES;

    
    //初始化卡片
    _container = [[YSLDraggableCardContainer alloc]init];
    _container.frame = CGRectMake(0, BarView.bottom, self.view.frame.size.width, self.view.frame.size.height);
    _container.backgroundColor = [UIColor clearColor];
    _container.dataSource = self;
    _container.delegate = self;
    _container.canDraggableDirection = YSLDraggableDirectionLeft | YSLDraggableDirectionRight | YSLDraggableDirectionUp;
    [self.view addSubview:_container];
    [_container reloadCardContainer];
    

    //无数据提示
    _Nodataimg = [UIImageView new];
//    NSString  *name = @"searchGif_YD.gif";
//    NSString  *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]] pathForResource:name ofType:nil];
//    NSData  *imageData = [NSData dataWithContentsOfFile:filePath];
//    self.Nodataimg.image =  [UIImage sd_animatedGIFWithData:imageData];;
    _Nodataimg.image = [UIImage imageNamed:@"empty_state_illustration"];
    _Nodataimg.hidden = YES;
    [self.view addSubview:_Nodataimg];
    [_Nodataimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.view).offset(-KScreenWidth/4);
        make.left.mas_equalTo(self.view).offset(KScreenWidth/4);
        make.top.mas_equalTo(self.view).offset(150*SCREEN_WIDTH_RATIO47);
        make.height.mas_offset(200*SCREEN_WIDTH_RATIO47);
    }];
    
    
    
    [self.view addSubview:BarView];

    


}
- (void)PhotoAuditdateView{
    
    if (!_PhotoAuditView) {
        _PhotoAuditView = [[UIView alloc] init];
        _PhotoAuditView.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
        
        _PhotoAuditView.hidden = NO;
        
        
        UIImageView *photoAuditImg = [[UIImageView alloc] initWithFrame:CGRectMake(5*SCREEN_WIDTH_RATIO47, 64+5*SCREEN_WIDTH_RATIO47, KScreenWidth-10*SCREEN_WIDTH_RATIO47, 450*SCREEN_WIDTH_RATIO47)];
        photoAuditImg.image = [UIImage imageNamed:@"home_card_empt_ai"];
        photoAuditImg.userInteractionEnabled = YES;
        [self.PhotoAuditView addSubview:photoAuditImg];
        
        
        
        CATransition * animation = [CATransition animation];
        
        animation.duration = 0.5;
        
        animation.type = kCATransitionPush;
        
        animation.subtype = kCATransitionFromRight;
        
        [_PhotoAuditView.layer addAnimation:animation forKey:nil];
        
        [UIView animateWithDuration:1.5 animations:^{
            
            [self.view addSubview:_PhotoAuditView];
            
            [self.view bringSubviewToFront:_PhotoAuditView];
        }];

    }
}
- (void)RemovePhotoAuditdateView{
    [_PhotoAuditView removeFromSuperview];
    
}
#pragma mark -- ==================选择筛选方法=================
- (void)rightBtnClick{
    [self.actionSheetTitle showGGActionSheet];

}
- (GGActionSheet *)actionSheetTitle{
    if (!_actionSheetTitle) {
        _actionSheetTitle = [GGActionSheet ActionSheetWithTitleArray:@[@"全部",@"只看女",@"只看男",@"自定义",@"消除位置并退出"] andTitleColorArray:@[[UIColor blackColor]] delegate:self];
        //取消按钮颜色设置
        _actionSheetTitle.cancelDefaultColor = [UIColor blackColor];
        //如果设置了选项颜色 当颜色数组和标题数组数量对不上时 多余标题使用选项默认颜色
        //如果设置了选项颜色 当颜色数组传空时，所有选项默认使用选项颜色
        //如果没设置选项颜色 数量对不上以及颜色数组为空时都使用默认黑色
        _actionSheetTitle.optionDefaultColor = [UIColor blackColor];
    }
    return _actionSheetTitle;
}
//弹框点击
- (void)GGActionSheetClickWithActionSheet:(GGActionSheet *)actionSheet Index:(int)index{
    
    if (index == 0) {
        _sex = @"2";
        _priorityStr = @"0";
        _page = 1;
        [self sendRequest];
    }else if (index == 1){
        _sex = @"0";
        _page = 1;
        _priorityStr = @"0";
        [self sendRequest];
    }else if (index == 2){
        _sex = @"1";
        _page = 1;
        _priorityStr = @"0";
        [self sendRequest];
    }else if (index == 3){
        NSLog(@"跳转");
        
        ScreeningViewController *Vc = [[ScreeningViewController alloc] init];
        Vc.presentjump = ^(NSString *minAge, NSString *maxAge, NSString *priorityStr, NSString *sexStr) {
            _minAge = minAge;
            _maxAge = maxAge;
            _priorityStr = priorityStr;
            _sex = sexStr;
            _page = 1;
            [self sendRequest];
        };
        [self.navigationController presentViewController:Vc animated:YES completion:nil];
    }else  {
        NSLog(@"清楚位置信息");
        
        _romptRemove = [[HomePromptRemoveView alloc] initWithFrame:CGRectMake(0, KScreenHeight-157, KScreenWidth, 157)];
        _romptRemove.delegate = self;
        
        
        CATransition *animation = [CATransition  animation];
        
        animation.duration = 0.5f;
        animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        animation.type = kCATransitionPush;
        animation.subtype = kCATransitionFromTop;
        [_romptRemove.layer addAnimation:animation forKey:@"animation1"];

        [self.view.window addSubview:_romptRemove];
    }
}
- (void)RemoveButtonClick:(UIButton *)sender{
            [self AddlocationView];
        [_romptRemove removeFromSuperview];
}

- (void)AddlocationView{
    _removeView = [[HomeRemovelocationView alloc] init];
    _removeView.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
    _removeView.delegate = self;
    _removeView.hidden = NO;
    CATransition * animation = [CATransition animation];
    
    animation.duration = 0.5;
    
    animation.type = kCATransitionPush;
    
    animation.subtype = kCATransitionFromRight;
    
    [_removeView.layer addAnimation:animation forKey:nil];
    
    [UIView animateWithDuration:1.5 animations:^{
        
        [self.view addSubview:_removeView];
        
        [self.view bringSubviewToFront:_removeView];
    }];
    
    
    [HQHttpManager updateUserWithUid:[HQHttpManager getUserId] mobile:nil photo:nil motto:nil sex:nil nickName:nil birthday:nil animal:nil height:nil weight:nil affection:nil email:nil job:nil hometown:nil activeSite:nil skill:nil wantSkill:nil zfb:nil zfbName:nil cardImg:nil video:nil privacy:@(0) isShield:nil successBlock:^(BOOL isSuccess, NSDictionary *resultDic) {
        if (isSuccess) {
            [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"privacy"];
            [defaults setObject:@"0" forKey:@"privacy"];
            [[NSUserDefaults standardUserDefaults] synchronize];
        }else{
            
        }
    }];

}
- (void)RemovelocationButton{
    [HQHttpManager updateUserWithUid:[HQHttpManager getUserId] mobile:nil photo:nil motto:nil sex:nil nickName:nil birthday:nil animal:nil height:nil weight:nil affection:nil email:nil job:nil hometown:nil activeSite:nil skill:nil wantSkill:nil zfb:nil zfbName:nil cardImg:nil video:nil privacy:@(1) isShield:nil successBlock:^(BOOL isSuccess, NSDictionary *resultDic) {
        if (isSuccess) {
            [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"privacy"];
            [defaults setObject:@"1" forKey:@"privacy"];
            [[NSUserDefaults standardUserDefaults] synchronize];

 
            
            CATransition * animation = [CATransition animation];
            
            animation.duration = 0.5;
            
            animation.type = kCATransitionPush;
            
            animation.subtype = kCATransitionFromRight;
            
            [_removeView.layer addAnimation:animation forKey:nil];
            
            [UIView animateWithDuration:1.5 animations:^{
                
            } completion:^(BOOL finished) {
                [_removeView removeFromSuperview];
 
            }];
   
        }
    }];

}
#pragma mark -- ==================选择城市代理方法=================
//城市选择初始化
- (void)createPickview{
    
    _cityView = [[CityView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
    _cityView.delegate = self;
    _leftBtn.enabled = NO;
    _btnLeft.enabled = NO;
    [_leftBtn setTitle:[NSString stringWithFormat:@"%@",_city] forState:UIControlStateNormal];
    
    [self.view addSubview:_cityView];
}
//选择
- (void)confirmAction:(UIButton *)sender cityStr:(NSString *)cityStr{
    _city = cityStr;
    [_leftBtn setTitle:[NSString stringWithFormat:@"%@",_city] forState:UIControlStateNormal];
    _leftBtn.enabled = YES;
    _btnLeft.enabled = YES;
    [self sendRequest];
    [_cityView removeFromSuperview];
    
}
//点击空白
- (void)baseViewTapAction:(UITapGestureRecognizer *)tap {
    [_leftBtn setTitle:[NSString stringWithFormat:@"%@",_city] forState:UIControlStateNormal];

    _leftBtn.enabled = YES;
    _btnLeft.enabled = YES;
    [_cityView removeFromSuperview];


}
//取消
- (void)cancleAction:(UIButton *)sender{
    _leftBtn.enabled = YES;
    _btnLeft.enabled = YES;
    [_leftBtn setTitle:[NSString stringWithFormat:@"%@",_city] forState:UIControlStateNormal];

    [_cityView removeFromSuperview];
}
#pragma mark -- =================网络请求==================
//卡片默认请求    
- (void)sendRequest{

    
    WEAKSELF
    [HcardHttpmanager sListWithUid:nil lon:@(longitude) lat:@(latitude) hometown:_city sex:_sex maxAge:_maxAge minAge:_minAge disatnce:_distance videoStatus:_videoUser page:@(_page) sort:_sort withRows:@(10) active:_priorityStr successBlock:^(BOOL isSuccess, NSDictionary *resultDic) {
        if (isSuccess) {
            [_dataArr removeAllObjects];
            _dataArr =[HcardUserModel mj_objectArrayWithKeyValuesArray:resultDic[@"res"]];
            if(_dataArr.count == 0){
                _page = 1;
            }
            
            if (_dataArr.count == 0) {
                
                _Nodataimg.hidden =NO;
                _slidingLab.hidden = YES;
                _rightsliImg.hidden = YES;
                _leftsliImg.hidden = YES;
                
            }else{
                
                _Nodataimg.hidden =YES;
                _slidingLab.hidden = NO;
                _rightsliImg.hidden = NO;
                _leftsliImg.hidden = NO;
                
            }
            
            
            [weakSelf.container reloadCardContainer];
            if ([[defaults objectForKey:@"privacy"] intValue] == 0) {
                [self AddlocationView];
            }else{
                
            }
        }else{
            _Nodataimg.image = [UIImage imageNamed:@"network_outage_illustration"];

        }
       

    }];
}

#pragma mark -- Selector ========================card   卡片=============================
//卡片点击方法
- (void)cardContainerView:(YSLDraggableCardContainer *)cardContainerView didSelectAtIndex:(NSInteger)index draggableView:(UIView *)draggableView
{
    
     self.cardView =(CardView *)[cardContainerView getCurrentView];
    [self.cardView.playerVideo pause];
    
    
    
    _Cardmodel = _dataArr[index];

    HomeStrangCollionViewController *vc = [[HomeStrangCollionViewController alloc] init];
        vc.UserId = _Cardmodel.uid;
    vc.Cardmodel = _Cardmodel;
    [self.navigationController pushViewController:vc animated:YES];
//    NSLog(@"++ index : %ld",(long)index);
}

#pragma mark -- YSLDraggableCardContainer DataSource
//数据初始化赋值
- (UIView *)cardContainerViewNextViewWithIndex:(NSInteger)index{
    _Cardmodel = _dataArr[index];
    
    CGFloat TopsegmentFloat ;
    
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad){
        NSLog(@"ipad");
        TopsegmentFloat =self.view.frame.size.width - 120*SCREEN_WIDTH_RATIO47;
    }else{
        TopsegmentFloat = self.view.frame.size.width - 20*SCREEN_WIDTH_RATIO47;
        NSLog(@"iphone or ipod");
    }
    
    _cardView = [[CardView alloc]initWithFrame:CGRectMake(15*SCREEN_WIDTH_RATIO47, 15*SCREEN_WIDTH_RATIO47, self.view.frame.size.width - 30*SCREEN_WIDTH_RATIO47, TopsegmentFloat)];
    _cardView.backgroundColor = [UIColor whiteColor];
    _cardView.delegate = self;
    //背景图
     [_cardView.imageView sd_setImageWithURL:[NSURL URLWithString:HttpImgUrl(_Cardmodel.photo)] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    
    [_cardView.likeCountButton setTitle:[NSString stringWithFormat:@"%ld人喜欢他",(long)_Cardmodel.wooCount] forState:UIControlStateNormal];
    
    //视频
    if ([_Cardmodel.videoStatus isEqualToString:@"1"]) {
        _cardView.playerVideo = [[ZGLVideoPlyer alloc]initWithFrame:_cardView.imageView.frame];

        UIBezierPath *maskPath;
        maskPath = [UIBezierPath bezierPathWithRoundedRect:_cardView.playerVideo.bounds
                                         byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)
                                               cornerRadii:CGSizeMake(7.0, 7.0)];
        
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = _cardView.playerVideo.bounds;
        maskLayer.path = maskPath.CGPath;
        _cardView.playerVideo.layer.mask = maskLayer;

        
        _cardView.playerVideo.hidden = YES;
        
        [_cardView addSubview:_cardView.playerVideo];
        
        _cardView.playerVideo.videoUrlStr =HttpImgUrl(_Cardmodel.video);
        
        _cardView.playerBtn.hidden = NO;
    }else{
        _cardView.playerBtn.hidden = YES;
    }
    //名字
    _cardView.Namelabel.text = _Cardmodel.nickName;
    //年龄
    [_cardView.sexAgeBtn setTitle:@(_Cardmodel.age).stringValue  forState:UIControlStateNormal];
    //星座
    
    
    _cardView.constellationLab.backgroundColor = [self getColorWithStr:_Cardmodel.star];
  _cardView.constellationLab.text = _Cardmodel.star;
    
    
    
    //属相
//    [view.AnimalImg sd_setImageWithURL:[NSURL URLWithString:HttpImgUrl(_Cardmodel.animalImg)]];
    _cardView.detailsLab.text = [NSString stringWithFormat:@"%@ %@公里 %@活跃",_Cardmodel.location,_Cardmodel.distance,_Cardmodel.activeTime];
    //性别
    if (_Cardmodel.sex == 0) {
        [_cardView.sexAgeBtn setBackgroundColor:ColorI(0xf28484)];

            [_cardView.sexAgeBtn setImage:[UIImage imageNamed:@"female"] forState:UIControlStateNormal];
    }else{
        [_cardView.sexAgeBtn setBackgroundColor:ColorI(0x84b9f2)];

            [_cardView.sexAgeBtn setImage:[UIImage imageNamed:@"male"] forState:UIControlStateNormal];
    }

 
    
    return _cardView;
}
- (UIColor *)getColorWithStr:(NSString *)starStr{
    
    NSArray * starArr = @[@"白羊座",@"天秤座",@"金牛座",@"天蝎座",@"双子座",@"射手座",@"巨蟹座",@"摩羯座",@"狮子座",@"处女座",@"双鱼座"];
    NSArray * colorArr = @[ColorI(0xd80808),ColorI(0xec3db0),ColorI(0x2898df),ColorI(0xa651c9),ColorI(0xff6839),ColorI(0x77ca69),ColorI(0xd16739),ColorI(0x30d3d5),ColorI(0x19d7ad),ColorI(0xecac3d),ColorI(0x32b576)];
    
    
    for (NSString * star in starArr) {
        if ([star isEqualToString:starStr]) {
            NSInteger index = [starArr indexOfObject:star];
            if (colorArr[index]) {
                return colorArr[index];
            }
        }
    }
    return ColorI(0xd80808);
}
//返回个数
- (NSInteger)cardContainerViewNumberOfViewInIndex:(NSInteger)index
{
    return _dataArr.count;
}
-(void)playBtnVideoView:(ZGLVideoPlyer *)plyerVideo{
    //传给控制器当前播放器View
    self.cardView.playerVideo =plyerVideo;
}
#pragma mark -- YSLDraggableCardContainer Delegate

//HomeStrangVC点击喜欢不喜欢按钮后通知调用方法
- (void)HomeStrongControllerRightDirection{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [_container movePositionWithDirection:YSLDraggableDirectionRight isAutomatic:YES];

    });
    
}

- (void)HomeStrongControllerLeftDirection{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [_container movePositionWithDirection:YSLDraggableDirectionLeft isAutomatic:YES];
        
    });
}

//滑动方法
- (void)cardContainerView:(YSLDraggableCardContainer *)cardContainerView didEndDraggingAtIndex:(NSInteger)index draggableView:(UIView *)draggableView draggableDirection:(YSLDraggableDirection)draggableDirection
{
    
    if (draggableDirection == YSLDraggableDirectionLeft) {
        [cardContainerView movePositionWithDirection:draggableDirection
                                         isAutomatic:NO];
        _Cardmodel = _dataArr[index];

        
        [HcardHttpmanager likeHerOrHimWithWid:_Cardmodel.uid state:@"0" successBlock:^(BOOL isSuccess, NSDictionary *resultDic) {
            if (isSuccess) {
                NSLog(@"%@",_Cardmodel.uid);

                NSLog(@"我不喜欢他========================");
            }
        } failure:^(NSError *error) {
            
        }];
    }
    
    
    if (draggableDirection == YSLDraggableDirectionRight) {
        [cardContainerView movePositionWithDirection:draggableDirection
                                         isAutomatic:NO];
        _Cardmodel = _dataArr[index];

        [HcardHttpmanager likeHerOrHimWithWid:_Cardmodel.uid state:@"1" successBlock:^(BOOL isSuccess, NSDictionary *resultDic) {
            if (isSuccess) {
                
                
                NSLog(@"%@",_Cardmodel.uid);

                NSLog(@"我喜欢他========================");
            }
        } failure:^(NSError *error) {
            
        }];

    }
}
//蒙层颜色
- (void)cardContainderView:(YSLDraggableCardContainer *)cardContainderView updatePositionWithDraggableView:(UIView *)draggableView draggableDirection:(YSLDraggableDirection)draggableDirection widthRatio:(CGFloat)widthRatio heightRatio:(CGFloat)heightRatio
{
    CardView *view = (CardView *)draggableView;
    
    if (draggableDirection == YSLDraggableDirectionDefault) {
        view.leftImg.alpha = 0;
        view.rightImg.alpha = 0;
    }
    
    if (draggableDirection == YSLDraggableDirectionLeft) {

                view.leftImg.alpha = widthRatio > 0.8 ? 0.8 : widthRatio;
    }
    
    if (draggableDirection == YSLDraggableDirectionRight) {

                view.rightImg.alpha = widthRatio > 0.8 ? 0.8 : widthRatio;
    }

}
//卡片初始化
- (void)cardContainerViewDidCompleteAll:(YSLDraggableCardContainer *)container;
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
        _page++;
        [self sendRequest];
    });
}
#pragma mark ==============定位==================
- (void)didLocation{
    if ([CLLocationManager locationServicesEnabled]) {
        //定位功能可用，开始定位
        self.locationManger = [[CLLocationManager alloc] init];
        self.locationManger.delegate = self;
        if ([[[UIDevice currentDevice] systemVersion] floatValue]  >= 8.0) {
            //使用期间
            [self.locationManger requestWhenInUseAuthorization];
        }
        [self.locationManger startUpdatingLocation];
    }else{
        //[self displayMessage:@"定位功能不可用,请打开定位功能"];
    }
}

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
    switch (status) {
        case kCLAuthorizationStatusNotDetermined:
            if ([self.locationManger respondsToSelector:@selector(requestAlwaysAuthorization)]) {
                [self.locationManger requestWhenInUseAuthorization];
            }
            break;
        default:
            break;
    }
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    NSLog(@"error");
}

// 6.0 以上调用这个函数
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
    CLLocation *newLocation = locations[0];
    CLLocationCoordinate2D oldCoordinate = newLocation.coordinate;
    longitude = oldCoordinate.longitude;
    latitude = oldCoordinate.latitude;
//    NSLog(@"旧的经度：%f,旧的纬度：%f",oldCoordinate.longitude,oldCoordinate.latitude);
    [self.locationManger stopUpdatingLocation];
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder reverseGeocodeLocation:newLocation
                   completionHandler:^(NSArray *placemarks, NSError *error){
                       for (CLPlacemark *placeMark in placemarks) {
                           NSDictionary *addressDic = placeMark.addressDictionary;
                           NSString *state=[addressDic objectForKey:@"State"];
                           NSString *city=[addressDic objectForKey:@"City"];
                           [[NSUserDefaults standardUserDefaults] setObject:city forKey:@"YD_CITY"];
                           [[NSUserDefaults standardUserDefaults] synchronize];
                           NSString *subLocality=[addressDic objectForKey:@"SubLocality"];
                           NSString *street=[addressDic objectForKey:@"Street"];
                           NSLog(@"所在城市====%@ %@ %@ %@", state, city, subLocality, street);
                     
                           [HQHttpManager putLocationWithUid:[HQHttpManager getUserId] lon:@(longitude) lat:@(latitude) location:[NSString stringWithFormat:@"%@  ",city] successBlock:^(BOOL isSuccess, NSDictionary *resultDic) {
                               
                           }];
                       }
                   }];
    
    [[NSUserDefaults standardUserDefaults] setObject:@(longitude).stringValue forKey:@"longitude"];
    [[NSUserDefaults standardUserDefaults] setObject:@(latitude).stringValue forKey:@"latitude"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (void)viewWillDisappear:(BOOL)animated{
    
    //离开控制器暂停播放方法
    [self.cardView.playerVideo pause];

}

-(void)dealloc {
    
    [[NSNotificationCenter defaultCenter] removeObserver:@"blackFriendNotification"];

}
@end
